# -*- coding: utf-8 -*-
"""
@Time    : 2024/6/26 17:05 
@Author  : ZhangShenao 
@File    : multi_process.py
@Desc    : 字符串的常用处理
"""

# 使用startswith()函数,判断字符串是否以指定的子串开头
s1 = 'happy'
print(f's1 is starts with "ha"? {s1.startswith('ha')}')  # s1 is starts with "ha"? True
print(f's1 is starts with "hay"? {s1.startswith('hay')}')  # s1 is starts with "hay"? False

# 使用endswith()函数,判断字符串是否以指定的子串结尾
print(f's1 is ends with "py"? {s1.endswith('py')}')  # s1 is ends with "py"? True
print(f's1 is ends with "apy"? {s1.endswith('apy')}')  # s1 is ends with "apy"? False

# 使用replace()函数,替换字符串中的指定子串,并返回一个新字符串
s2 = s1.replace('y', 'iness')
print(f's2 is {s2}')  # s2 is happiness

# 使用strip()函数,去除字符串两端的空白字符,包括空格、换行符、制表符等
s3 = '\thello world   \n'
s4 = s3.strip()
print(f's4 is {s4}')  # s4 is hello world

# 使用split()函数,将字符串按照指定的分隔符进行分割,并返回一个列表
s5 = 'a,b,c,d,e'
splits = s5.split(',')
print(f'splits is {splits}')  # splits is ['a', 'b', 'c', 'd', 'e']

# 使用join()函数,将列表中的元素按照指定的分隔符进行连接,并返回一个字符串
s6 = '-'.join(['a', 'b', 'c', 'd', 'e'])
print(f's6 is {s6}')  # s6 is a-b-c-d-e

# 使用upper()和lower()函数,将字符串中的所有字母转换为大写和小写,并返回一个新字符串
s7 = 'Hello World'
s7_upper = s7.upper()
s7_lower = s7.lower()
print(f's7_upper is {s7_upper} and s7_lower is {s7_lower}')
